fix(segment-button): update checked state on render#26970
Conversation
|
|
|
Does this need to be tagged for review? What can I do to help this along? |
|
Opening this up for review. I identified that calling I left this in draft for a bit because I wanted to see if there is an easy way to write tests around this (the reproduction requires a bit of rxjs + Angular). I haven't had the time to do so yet. I think the risk of this change is incredibly low (at worst, it is calling |
| }; | ||
| } | ||
|
|
||
| componentDidLoad() { |
There was a problem hiding this comment.
Threading for discussion:
Are we confident this is a v7 regression? When I triaged this in #26830 (comment), I was able to reproduce this in v6, but perhaps I reproduced a different issue.
There was a problem hiding this comment.
Alternatively: Is this a bug that's always been there but is now causing issues because of v7 changes? (possibly the initializeNextTick change?)
There was a problem hiding this comment.
Ok I did a bit more digging and this is (fortunately) not an Ionic v7 regression. However, it is much more noticeable now that the initializeNextTick config was removed in Ionic v7.
The problem here is that if the value property on ion-segment-button is set asynchronously, the updateState method is not called again.
So given the following:
<ion-segment value="general">
<ion-segment-button>General</ion-segment-button>
</ion-segment>If you were to asynchronously set the value of the segment button to "general", the segment button would not appear checked.
Below is a test you can use to verify the fix.
segment/test/async/segment.e2e.ts
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('segment: async', () => {
test('should set checked state when value is set asynchronously', async ({ page, skip }) => {
skip.rtl();
skip.mode('md');
await page.setContent(`
<ion-segment value="first">
<ion-segment-button>First</ion-segment-button>
</ion-segment>
`);
const segmentButton = page.locator('ion-segment-button');
await segmentButton.evaluate((el: HTMLIonSegmentButtonElement) => el.value = 'first');
await page.waitForChanges();
await expect(segmentButton).toHaveClass(/segment-button-checked/);
});
});There was a problem hiding this comment.
If possible, we should merge this into main so v6 devs can benefit from this fix too.
|
Thanks so much guys! Really happy you were able to figure out the root cause of what's happening. |
|
Just looping back on this. Anything I can do to help? I noticed it didn't make it into v7, and the issue is occurring quite consistently for my application now. Sorry to be a pest! But I've seen a few releases out and this seems so close to the finish line. |
|
We pulled this into the next sprint to take another look at. |
|
@sean-perkins I added the correct fix as well as a test. Mind taking a look when you get a chance? (I changed from an E2E to a unit test too) |
|
Looks good to me, I resolved the merge conflict with We can cherry pick the commit into the v6 release branch. |
<!-- Please refer to our contributing documentation for any questions on submitting a pull request, or let us know here if you need any help: https://ionicframework.com/docs/building/contributing --> Please check if your PR fulfills the following requirements: - [ ] Tests for the changes have been added (for bug fixes / features) - [ ] Docs have been reviewed and added / updated if needed (for bug fixes / features) - Some docs updates need to be made in the `ionic-docs` repo, in a separate PR. See the [contributing guide](https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation) for details. - [x] Build (`npm run build`) was run locally and any changes were pushed - [x] Lint (`npm run lint`) has passed locally and any fixes were made for failures <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): <!-- Please describe the current behavior that you are modifying. --> In v7, asynchronously assigning a value to `ion-segment` and `ion-segment-button` can cause the `ion-segment` to render without an active value (segment button does not show as checked). <!-- Issues are required for both bug fixes and features. --> Issue URL: resolves #26830 <!-- Please describe the behavior or changes that are being added by this PR. --> - The `ion-segment-button` checked state is synced with the parent `ion-segment`, when the component finishes the initial render. - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Dev-build: `7.0.0-dev.11678736268.18a0beb1` ✅ --------- Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>
<!-- Please refer to our contributing documentation for any questions on submitting a pull request, or let us know here if you need any help: https://ionicframework.com/docs/building/contributing --> ## Pull request checklist Please check if your PR fulfills the following requirements: - [ ] Tests for the changes have been added (for bug fixes / features) - [ ] Docs have been reviewed and added / updated if needed (for bug fixes / features) - Some docs updates need to be made in the `ionic-docs` repo, in a separate PR. See the [contributing guide](https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation) for details. - [x] Build (`npm run build`) was run locally and any changes were pushed - [x] Lint (`npm run lint`) has passed locally and any fixes were made for failures ## Pull request type <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> In v7, asynchronously assigning a value to `ion-segment` and `ion-segment-button` can cause the `ion-segment` to render without an active value (segment button does not show as checked). <!-- Issues are required for both bug fixes and features. --> Issue URL: resolves #26830 ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - The `ion-segment-button` checked state is synced with the parent `ion-segment`, when the component finishes the initial render. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Dev-build: `7.0.0-dev.11678736268.18a0beb1` ✅ --------- Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>
<!-- Please refer to our contributing documentation for any questions on submitting a pull request, or let us know here if you need any help: https://ionicframework.com/docs/building/contributing --> ## Pull request checklist Please check if your PR fulfills the following requirements: - [ ] Tests for the changes have been added (for bug fixes / features) - [ ] Docs have been reviewed and added / updated if needed (for bug fixes / features) - Some docs updates need to be made in the `ionic-docs` repo, in a separate PR. See the [contributing guide](https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation) for details. - [x] Build (`npm run build`) was run locally and any changes were pushed - [x] Lint (`npm run lint`) has passed locally and any fixes were made for failures ## Pull request type <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> In v7, asynchronously assigning a value to `ion-segment` and `ion-segment-button` can cause the `ion-segment` to render without an active value (segment button does not show as checked). <!-- Issues are required for both bug fixes and features. --> Issue URL: resolves #26830 ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - The `ion-segment-button` checked state is synced with the parent `ion-segment`, when the component finishes the initial render. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Dev-build: `7.0.0-dev.11678736268.18a0beb1` ✅ --------- Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>
Pull request checklist
Please check if your PR fulfills the following requirements:
ionic-docsrepo, in a separate PR. See the contributing guide for details.npm run build) was run locally and any changes were pushednpm run lint) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
In v7, asynchronously assigning a value to
ion-segmentandion-segment-buttoncan cause theion-segmentto render without an active value (segment button does not show as checked).Issue URL: resolves #26830
What is the new behavior?
ion-segment-buttonchecked state is synced with the parention-segment, when the component finishes the initial render.Does this introduce a breaking change?
Other information
Dev-build:
7.0.0-dev.11678736268.18a0beb1✅